package com.example.lightenergypolymerize.util;

import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;



@RestControllerAdvice
public class ExceptionAdvice {
    @ExceptionHandler(BindException.class)//注意BindException的包不要导错
    public ResponseEntity handleException(BindException e) {
        return ResponseEntity.fail(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResponseEntity handleException(Exception e) {
        return ResponseEntity.fail(e.getMessage());
    }
}
